var app = getApp();

Page({
    data: {
        _is_load: !0,
        is_akey: !1,
        t_card_id: 0,
        card_info: [],
        my_card_info: []
    },
    onLoad: function(a) {
        var t = this;
        app.util.footer(this), app.util.getUserInfo(function(a) {
            t.setData({
                userInfo: a
            });
        });
        var e = a.card_id.split(","), i = e[0], d = e[1];
        t.setData({
            t_card_id: i,
            popenid: d
        }), app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                0 == a.data.errno && t.setData({
                    my_card_info: a.data.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/Setup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                t.setData({
                    setup: a.data.data,
                    apikey: a.data.data.apikey
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetGun",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                t.setData({
                    guns: a.data.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/VideoSetup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                t.setData({
                    videosetup: a.data.data,
                    _is_load: !1
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        this.Onexchange(1), this.setData({
            sysinfo: app.globalData.sysinfo,
            _is_load: !1
        });
    },
    Onexchange: function() {
        var d = this;
        app.util.request({
            url: "entry/wxapp/GetCardTr",
            data: {
                m: "bbyscm_card",
                card_id: d.data.t_card_id,
                popenid: d.data.popenid
            },
            success: function(a) {
                if (0 == a.data.data.akey) if (0 == a.data.errno) if (a.data.data.curr_openid == a.data.data.openid) wx.reLaunch({
                    url: "../index/index"
                }); else {
                    if (1 == a.data.data.exchange) var t = a.data.data.mobile2, e = a.data.data.mobile, i = a.data.data.cardname; else if (1 == a.data.data.harass) {
                        t = a.data.data.mobile2.substr(0, 4) + "*****" + a.data.data.mobile2.substr(9), 
                        e = a.data.data.mobile.substr(0, 4) + "*****" + a.data.data.mobile.substr(8);
                        if (1 == a.data.data.sex) i = a.data.data.cardname.substr(0, 1) + "先生" + a.data.data.cardname.substr(7); else if (0 == a.data.data.sex) i = a.data.data.cardname.substr(0, 1) + "女士" + a.data.data.cardname.substr(7); else i = a.data.data.cardname.substr(0, 1) + a.data.data.job + a.data.data.cardname.substr(7);
                    } else t = a.data.data.mobile2, e = a.data.data.mobile, i = a.data.data.cardname;
                    d.setData({
                        card_info: a.data.data,
                        cardname: i,
                        mobile: e,
                        mobile2: t,
                        glo_is_load: !1
                    }), wx.setNavigationBarTitle({
                        title: i + "的名片"
                    }), 0 == a.data.data.fenxiang && wx.hideShareMenu();
                } else d.setData({
                    is_load_more: !1
                }); else d.setData({
                    is_akey: !0
                });
            }
        });
    },
    onHide: function() {},
    onNavigateTap: function(a) {
        wx.navigateTo({
            url: a.currentTarget.dataset.url
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    card_collection_bind: function(a) {
        var t = this, e = a.currentTarget.id, i = a.currentTarget.dataset.openid, d = t.data.my_card_info.id;
        d ? d != e && app.util.request({
            url: "entry/wxapp/ApiPostClick",
            data: {
                m: "bbyscm_card",
                to_cardid: e,
                to_openid: i,
                my_cardid: d
            },
            success: function(a) {
                0 == a.data.errno ? (t.setData({
                    card_info: [],
                    glo_is_load: !1
                }), t.Onexchange(1)) : t.setData({
                    is_load_more: !1
                });
            }
        }) : wx.showModal({
            title: "提示",
            content: "你还没有创建名片！不能收藏操作！",
            showCancel: !1,
            success: function() {
                wx.navigateTo({
                    url: "../edit/card-edit"
                });
            }
        });
    },
    card_collection_d: function(a) {
        var t = this, e = a.currentTarget.id, i = a.currentTarget.dataset.openid, d = t.data.my_card_info.id;
        d != e && app.util.request({
            url: "entry/wxapp/ApiPostClickd",
            data: {
                m: "bbyscm_card",
                to_cardid: e,
                to_openid: i,
                my_cardid: d
            },
            success: function(a) {
                0 == a.data.errno ? (t.setData({
                    card_info: [],
                    glo_is_load: !1
                }), t.Onexchange(1)) : t.setData({
                    is_load_more: !1
                });
            }
        });
    },
    exchange_card: function(a) {
        var t = this;
        JSON.stringify(a.detail.value);
        var e = a.detail.formId, i = t.data.t_card_id, d = t.data.my_card_info.id;
        d ? app.util.request({
            url: "entry/wxapp/PostExchange",
            data: {
                m: "bbyscm_card",
                form_id: e,
                cardid: i,
                my_cardid: d
            },
            success: function(a) {
                0 == a.data.errno ? (t.setData({
                    card_info: [],
                    glo_is_load: !1
                }), t.Onexchange(1)) : t.setData({
                    is_load_more: !1
                });
            }
        }) : wx.showModal({
            title: "提示",
            content: "你还没有创建名片！无权与别人交换！",
            showCancel: !1,
            success: function() {
                wx.navigateTo({
                    url: "../edit/card-edit"
                });
            }
        });
    },
    call_phone_bind: function(a) {
        var t = a.currentTarget.id;
        "" != t && wx.makePhoneCall({
            phoneNumber: t
        });
    },
    show_img: function(a) {
        wx.previewImage({
            current: a.currentTarget.dataset.src,
            urls: this.data.card_info.imgs
        });
    },
    show_weixin_img: function(a) {
        wx.previewImage({
            current: a.currentTarget.dataset.src,
            urls: [ a.currentTarget.dataset.src ]
        });
    },
    onShareAppMessage: function() {
        var a = this;
        return {
            title: a.data.setup.fxtext + a.data.card_info.cardname + a.data.setup.fxtexth,
            desc: a.data.setup.fxtext + a.data.card_info.cardname + a.data.setup.fxtexth,
            path: "pages/card/info/info?card_id=" + a.data.card_info.id,
            img: a.data.imgs,
            imgs: [],
            success: function(a) {
                wx.showToast({
                    title: "转发成功",
                    icon: "success",
                    duration: 1e3,
                    mask: !0
                });
            },
            fail: function(a) {
                wx.showToast({
                    title: "转发失败",
                    icon: "error",
                    duration: 1e3,
                    mask: !0
                });
            }
        };
    },
    open: function() {
        this.setData({
            condition: !this.data.condition
        });
    },
    cardEditBtn: function(a) {
        var t = a.target.dataset.id;
        this.setData({
            condition: !this.data.condition
        }), wx.navigateTo({
            url: "../edit/card-edit?cardid=" + t
        });
    },
    cardEditBtn2: function(a) {
        var t = a.target.dataset.id;
        wx.navigateTo({
            url: "../edit/card-edit?cardid=" + t
        });
    },
    cardEditmore: function(a) {
        var t = a.target.dataset.id;
        this.setData({
            condition: !this.data.condition
        }), wx.navigateTo({
            url: "../edit_more/edit_more?cardid=" + t
        });
    },
    cardEditmore2: function(a) {
        var t = a.target.dataset.id;
        wx.navigateTo({
            url: "../edit_more/edit_more?cardid=" + t
        });
    },
    edit_imgs: function(a) {
        var t = a.target.dataset.id;
        this.setData({
            condition: !this.data.condition
        }), wx.navigateTo({
            url: "../edit_imgs/edit_imgs?cardid=" + t
        });
    },
    edit_imgs2: function(a) {
        var t = a.target.dataset.id;
        wx.navigateTo({
            url: "../edit_imgs/edit_imgs?cardid=" + t
        });
    },
    edit_privacy: function(a) {
        var t = a.target.dataset.id;
        this.setData({
            condition: !this.data.condition
        }), wx.navigateTo({
            url: "../edit_privacy/edit_privacy?cardid=" + t
        });
    },
    edit_video: function(a) {
        var t = a.target.dataset.id;
        this.setData({
            condition: !this.data.condition
        }), wx.navigateTo({
            url: "../edit_video/edit_video?cardid=" + t
        });
    },
    go_home_bind: function() {
        wx.navigateTo({
            url: "../index/index"
        });
    },
    add_home_bind: function() {
        wx.navigateTo({
            url: "../edit/card-edit"
        });
    },
    play_video: function(a) {
        var t = a.currentTarget.id;
        wx.navigateTo({
            url: "../video/video?cardid=" + t
        });
    },
    open_map: function(a) {
        var t = a.currentTarget.dataset.lat, e = a.currentTarget.dataset.lon;
        "0" != t ? wx.openLocation({
            latitude: parseFloat(t),
            longitude: parseFloat(e),
            scale: 28
        }) : wx.showToast({
            image: "../../resource/images/static/error.png",
            title: "座标错误,无法定位!"
        });
    },
    import_myphone_bind: function() {
        var a = this;
        wx.addPhoneContact({
            photoFilePath: a.data.card_info.avater || "",
            firstName: a.data.card_info.cardname || "",
            nickName: a.data.card_info.username || "",
            organization: a.data.card_info.company || "",
            title: a.data.card_info.job || "",
            mobilePhoneNumber: a.data.card_info.mobile || "",
            addressStreet: a.data.card_info.weixin || "",
            weChatNumber: a.data.card_info.nickName || "",
            email: a.data.card_info.email || "",
            success: function() {}
        });
    },
    nav_home: function() {
        wx.switchTab({
            url: "../index/index"
        });
    },
    nav_back: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    getcodes: function(a) {
        console.log("提交", a);
        var i = !1, t = a.currentTarget.dataset.id;
        app.util.request({
            url: "entry/wxapp/GetCode",
            data: {
                m: "bbyscm_card",
                cardid: t,
                path: "pages/card/info/info?card_id=" + t
            },
            method: "POST",
            success: function(a) {
                if (0 == a.data.errno) {
                    var t = a.data.data;
                    wx.previewImage({
                        urls: [ t ]
                    }), setTimeout(function() {
                        i = !0, wx.hideToast();
                    }, 2e3);
                    var e = a.data.data;
                    wx.downloadFile({
                        url: e,
                        success: function(a) {
                            wx.saveImageToPhotosAlbum({
                                filePath: a.tempFilePath,
                                success: function(a) {},
                                fail: function(a) {
                                    "saveImageToPhotosAlbum:fail auth deny" === a.errMsg && wx.openSetting({
                                        success: function(a) {
                                            a.authSetting["scope.writePhotosAlbum"];
                                        }
                                    });
                                }
                            });
                        }
                    }), i = !0, wx.hideToast();
                }
            }
        }), setTimeout(function() {
            i || wx.showToast({
                title: "请稍后...",
                icon: "loading",
                duration: 2e3
            });
        }, 2e3);
    },
    onNavigateTaptb: function(a) {
        var t = a.currentTarget.dataset.url, e = a.currentTarget.dataset.wx_appid, i = a.currentTarget.dataset.wx_path;
        e ? wx.navigateToMiniProgram({
            appId: e,
            path: i,
            extraData: {
                foo: "bar"
            },
            envVersion: "develop",
            success: function(a) {}
        }) : wx.navigateTo({
            url: "../info/info?card_id=" + t
        });
    },
    ai_edit: function(a) {
        wx.navigateTo({
            url: "../ai_ocr/ai_ocr?id=" + this.data.t_card_id
        });
    }
});